﻿/**********************************************
* @brief         地图UI
                    参考 QGroundControl-4.3.0 的代码
                    Tile: 即瓦片，图块
* @author        Wei
* @date          2024-10-18
**********************************************/
import QtQuick          2.15
import QtQuick.Controls 2.15
import QtQuick.Window   2.15
import QtQuick.Dialogs  1.3
import QtQuick.Layouts  1.11
import QtLocation       5.15
import QtPositioning    5.15

import MapWidgetGlobal    1.0
import FileDialogHelper   1.0
import "qrc:/rc/qml/"

Item {  
    id: _root
    visible: true  
    width: 640
    height: 480

    property string mapKey:             "lastMapType"
    property string mapType:            _defaultMapType
    readonly property string fontFamily: uiPref.fontFamily
    property var    savedCenter:        undefined
    property real   savedZoom:          3
    property string savedMapType:       ""
    property bool   isMapInteractive:   false

    property var _mapModel: MapWidgetGlobal.mapModel
    property var    _currentSelection:  null
    readonly property color _rectColor: Qt.rgba(0x22/0xFF, 0x22/0xFF, 0x22/0xFF, 0.85)
    readonly property color _buttonColor: uiPref.buttonColor
    readonly property color _buttonTextColor: uiPref.buttonTextColor
    readonly property color  _warningTextColor: uiPref.warningTextColor
    property bool   _showPreview:       true
    property bool   _tooManyTiles:      MapWidgetGlobal.mapEngineManager.tileCount > _maxTilesForDownload
    property int _maxTilesForDownload: MapWidgetGlobal.appSettings.value("Map/MaxTilesForDownload", 100000)
    property bool   _defaultSet:        _root && _root._currentSelection && _root._currentSelection.defaultSet
    property real   _margins:           10 * 0.5
    property real   _buttonSize:        10 * 12
    //property real   _bigButtonSize:     10 * 16
    property var    _mapAdjustedColor:  _map.isSatelliteMap ? "white" : "black"
    readonly property real sliderTouchArea: 10 * 3
    readonly property real minZoomLevel:    1
    readonly property real maxZoomLevel:    20
    property bool   _followVehicle:        true
    readonly property string _tiandituProvider: "Tianditu"
    readonly property string _defaultMapType: "Bing Satellite"

    UiPref { id: uiPref }

    Component.onCompleted: {
        mapType = MapWidgetGlobal.appSettings.value("Map/Type", "")
        if (mapType === "") {
            mapType = _defaultMapType
            MapWidgetGlobal.appSettings.setValue("Map/Type", mapType)
        }
        MapWidgetGlobal.mapEngineManager.loadTileSets()
        for (var i = 0; i < _map.supportedMapTypes.length; i++) {
            console.log("supported map type: ", _map.supportedMapTypes[i].name)
        }

        // Tianditu Cia, Tianditu Cva, Tianditu Vec, Tianditu Img
        updateActiveMapType(_map, mapType)
        savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2), false)
        MapWidgetGlobal.mapEngineManager.saveSetting(mapKey, mapType)
    }

    function handleChanges() {
        if(isMapInteractive) {
            var xl = 0
            var yl = 0
            var xr = _map.width.toFixed(0) - 1  // Must be within boundaries of visible map
            var yr = _map.height.toFixed(0) - 1 // Must be within boundaries of visible map
            var c0 = _map.toCoordinate(Qt.point(xl, yl), false)
            var c1 = _map.toCoordinate(Qt.point(xr, yr), false)
            MapWidgetGlobal.mapEngineManager.updateForCurrentView(c0.longitude, c0.latitude, c1.longitude, c1.latitude, sliderMinZoom.value, sliderMaxZoom.value, mapType)
        }
    }

    // 未使用，目前暂时使用 updateActiveMapType 代替
    function updateMap() {
        for (var i = 0; i < _map.supportedMapTypes.length; i++) {
            if (mapType === _map.supportedMapTypes[i].name) {
                _map.activeMapType = _map.supportedMapTypes[i]
                console.log("set active map type: ", _map.activeMapType.name)
                handleChanges()
                return
            }
        }
    }
    // 更新地图显示类型
    function updateActiveMapType(control, param) {
        for (var i = 0; i < control.supportedMapTypes.length; i++) {
            if (param === control.supportedMapTypes[i].name) {
                control.activeMapType = control.supportedMapTypes[i]
                console.log("set active map type: ", control.activeMapType.name)
                return
            }
        }
    }

    function addNewSet() {
        isMapInteractive = true
        // 添加新图集的界面上的地图类型选择被我删除了，所以这里注释
        // mapType = _fmSettings.mapProvider.value + " " + _fmSettings.mapType.value
        resetMapToDefaults()
        handleChanges()
        // 该文件范围内地图始终显示 _map.visible = true
        tileSetListView.visible = false
        infoView.visible = false
        exporTilesView.visible = false
        addNewSetView.visible = true
    }

    function showList() {
        exporTilesView.visible = false
        isMapInteractive = false
        // 该文件范围内地图始终显示 _map.visible = false
        tileSetListView.visible = true
        infoView.visible = false
        addNewSetView.visible = false
        MapWidgetGlobal.mapEngineManager.resetAction();
    }

    function showExport() {
        isMapInteractive = false
        // 该文件范围内地图始终显示 _map.visible = false
        tileSetListView.visible = false
        infoView.visible = false
        addNewSetView.visible = false
        exporTilesView.visible = true
    }

    function showInfo() {
        isMapInteractive = false
        if(_currentSelection && !_root._currentSelection.deleting) {
            enterInfoView()
        } else
            showList()
    }

    function toRadian(deg) {
        return deg * Math.PI / 180
    }

    function toDegree(rad) {
        return rad * 180 / Math.PI
    }

    function midPoint(lat1, lat2, lon1, lon2) {
        var dLon = toRadian(lon2 - lon1);
        lat1 = toRadian(lat1);
        lat2 = toRadian(lat2);
        lon1 = toRadian(lon1);
        var Bx = Math.cos(lat2) * Math.cos(dLon);
        var By = Math.cos(lat2) * Math.sin(dLon);
        var lat3 = Math.atan2(Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By));
        var lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
        return QtPositioning.coordinate(toDegree(lat3), toDegree(lon3))
    }

    function enterInfoView() {
        // 该文件范围内地图始终显示 _map.visible = true
        isMapInteractive = false
        savedCenter = _map.toCoordinate(Qt.point(_map.width / 2, _map.height / 2), false)
        savedZoom = _map.zoomLevel
        savedMapType = mapType
        if(!_root._currentSelection.defaultSet) {
            mapType = _root._currentSelection.mapTypeStr
            _map.center = midPoint(_root._currentSelection.topleftLat, _root._currentSelection.bottomRightLat, _root._currentSelection.topleftLon, _root._currentSelection.bottomRightLon)
            //-- Delineate Set Region
            var x0 = _root._currentSelection.topleftLon
            var x1 = _root._currentSelection.bottomRightLon
            var y0 = _root._currentSelection.topleftLat
            var y1 = _root._currentSelection.bottomRightLat
            mapBoundary.topLeft     = QtPositioning.coordinate(y0, x0)
            mapBoundary.bottomRight = QtPositioning.coordinate(y1, x1)
            mapBoundary.visible = true
            // Some times, for whatever reason, the bounding box is correct (around ETH for instance), but the rectangle is drawn across the planet.
            // When that happens, the "_map.fitViewportToMapItems()" below makes the map to zoom to the entire earth.
            //console.log("Map boundary: " + mapBoundary.topLeft + " " + mapBoundary.bottomRight)
            _map.fitViewportToMapItems()
        }
        tileSetListView.visible = false
        addNewSetView.visible = false
        infoView.visible = true
    }

    function leaveInfoView() {
        mapBoundary.visible = false
        _map.center = savedCenter
        _map.zoomLevel = savedZoom
        mapType = savedMapType
    }

    function resetMapToDefaults() {
        //todo: _map.center = MapWidgetGlobal.flightMapPosition
        //todo: _map.zoomLevel = MapWidgetGlobal.flightMapZoom
    }

    Plugin {
        id: mapPlugin
        // "CustomMap"
        // "osm", "mapboxgl", "esri", ...
        name: "CustomMap"
    }

    FileDialogHelper { id: fileDialogHelper }

    // 地图上显示的载具
    MapItemMovingPoint {
        id: vehicle
        imagePath: "qrc:/rc/image/vehicle.svg"
        coordinate: QtPositioning.coordinate(34.162214, 107.902628)
        visible: true
    }
    // 地图上显示的转台
    MapItemMovingPoint {
        id: home
        imagePath: "qrc:/rc/image/home.svg"
        coordinate: QtPositioning.coordinate(34.162214, 107.902628)
        visible: true
    }


    onMapTypeChanged: {
        updateMap()
        if(isMapInteractive) {
            MapWidgetGlobal.mapEngineManager.saveSetting(mapKey, mapType)  // 这行代码有啥用？
        }
    }

    // 保存 ?加载 ? 对话框 "Tile Sets (*.qgctiledb)"
    FileDialog {
        id:             fileDialogSave
        nameFilters:    ["Tile Sets (*.tiledb)"]
        onAccepted: {
            if (MapWidgetGlobal.mapEngineManager.exportSets(fileDialogHelper.urlToLocalFile(fileUrl))) {
                exportToDiskProgress.open()
            } else {
                showList()
            }
            close()
        }
    }

    FileDialog {
        id:             fileDialogLoad
        nameFilters:    ["Tile Sets (*.tiledb)"]
        onAccepted: {
            if(!MapWidgetGlobal.mapEngineManager.importSets(fileDialogHelper.urlToLocalFile(fileUrl))) {
                showList();
            }
            close()
        }
    }

    // Critical 消息框  id: errorDialog
    MessageDialog {
        id:         errorDialog
        visible:    false
        text:       MapWidgetGlobal.mapEngineManager.errorMessage
        icon:       StandardIcon.Critical
        standardButtons: StandardButton.Ok
        title:      "错误"
        onYes: {
            errorDialog.visible = false
        }
    }

    Component {
        id: mapSettingsDialogComponent
        MapPopupDialog {
            title: "地图参数设置"
            buttons:    StandardButton.Save | StandardButton.Cancel
            onAccepted: {
                MapWidgetGlobal.appSettings.setValue("Map/TiandituAccessToken", tiandituAccessToken.text)
                MapWidgetGlobal.appSettings.setValue("Map/TiandituSLD", tiandituSLD.text)
            }
            Column {
                spacing: 10 / 2
                MapLabel {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    wrapMode:       Text.WordWrap
                    text:           "地图类型："
                }
                ComboBox {
                    id:             mapTypeCombo
                    model:          MapWidgetGlobal.mapEngineManager.mapList
                    height:         30
                    onActivated: {
                        mapType = textAt(index)
                        MapWidgetGlobal.appSettings.setValue("Map/Type", mapType)
                    }
                    Component.onCompleted: {
                        var index = mapTypeCombo.find(mapType)
                        if (index === -1) {
                            console.warn("Active map name not in combo", mapType)
                        } else {
                            mapTypeCombo.currentIndex = index
                        }
                    }
                }
                Item { width: 1; height: 1; visible: mapType.startsWith(_tiandituProvider) }
                MapLabel { text: "天地图 Access Token"; visible: mapType.startsWith(_tiandituProvider) }
                MapTextField {
                    id:                 tiandituAccessToken
                    text: MapWidgetGlobal.appSettings.value("Map/TiandituAccessToken")
                    visible: mapType.startsWith(_tiandituProvider)
                }
                MapLabel { text: "该项修改后需要重启软件！"; visible: mapType.startsWith(_tiandituProvider) }
                Item { width: 1; height: 1; visible: mapType.startsWith(_tiandituProvider) }
                MapLabel { text: "天地图二级域名"; visible: mapType.startsWith(_tiandituProvider) }
                MapTextField {
                    id:                 tiandituSLD
                    text: MapWidgetGlobal.appSettings.value("Map/TiandituSLD")
                    visible: mapType.startsWith(_tiandituProvider)
                }
                MapLabel { text: "该项修改后需要重启软件！"; visible: mapType.startsWith(_tiandituProvider) }
            }
        }
    }


    // 离线地图选项
    Component {
        id: optionsDialogComponent
        MapPopupDialog {
            title: "地图下载选项"
            buttons:    StandardButton.Save | StandardButton.Cancel
            onAccepted: {
                MapWidgetGlobal.mapEngineManager.maxDiskCache = parseInt(maxCacheSize.text)
                MapWidgetGlobal.mapEngineManager.maxMemCache  = parseInt(maxCacheMemSize.text)
                _maxTilesForDownload = parseInt(maxTilesForDownload.text)
                MapWidgetGlobal.appSettings.setValue("Map/MaxTilesForDownload", _maxTilesForDownload)
            }
            Column {
                spacing: 10 / 2
                MapLabel { text:       qsTr("最大硬盘缓存大小(MB)：") }
                MapTextField {
                    id:                 maxCacheSize
                    maximumLength:      6
                    inputMethodHints:   Qt.ImhDigitsOnly
                    validator:          IntValidator {bottom: 1; top: 262144;}
                    text:               MapWidgetGlobal.mapEngineManager.maxDiskCache
                }
                Item { width: 1; height: 1 }
                MapLabel {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    wrapMode:       Text.WordWrap
                    text:           qsTr("最大缓存大小(MB)：")
                }
                MapTextField {
                    id:                 maxCacheMemSize
                    maximumLength:      4
                    inputMethodHints:   Qt.ImhDigitsOnly
                    validator:          IntValidator {bottom: 1; top: 1024;}
                    text:               MapWidgetGlobal.mapEngineManager.maxMemCache
                }
                MapLabel {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    wrapMode:       Text.WordWrap
                    font.pointSize: 8
                    text:           "缓存更改后需要重启软件来使其生效。"
                }
                Item { width: 1; height: 1 }
                MapLabel {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    wrapMode:       Text.WordWrap
                    text:           qsTr("可存储图块数量：")
                }
                MapTextField {
                    id:                 maxTilesForDownload
                    maximumLength:      8
                    inputMethodHints:   Qt.ImhDigitsOnly
                    validator:          IntValidator {bottom: 10000; top: 10000000;}
                    text:               MapWidgetGlobal.appSettings.value("Map/MaxTilesForDownload", 100000)
                }

            }
        }
    }

    // 确认删除对话框
    Component {
        id: deleteConfirmationDialogComponent
        MapSimpleMessageDialog {
            map:        _root
            title:      "删除确认"
            text:       _root._currentSelection.defaultSet ?
                            "即将删除所有图块，且包含您自己创建的那些图块集。\n\n您确定要这么做吗？" :
                            "删除 %1 和所有相关图块。\n\n您确定要这么做吗？".arg(_root._currentSelection.name)
            buttons:    StandardButton.Yes | StandardButton.No

            onAccepted: {
                MapWidgetGlobal.mapEngineManager.deleteTileSet(_root._currentSelection)
                leaveInfoView()
                showList()
            }
        }
    }

    // 地图显示区域
    Item {
        anchors.fill:       parent

        // FlightMap
        Map {
            id: _map
            anchors.fill: parent
            //-- Qt 5.9 has rotation gesture enabled by default. Here we limit the possible gestures.
            gesture.acceptedGestures:   MapGestureArea.PinchGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture
            gesture.flickDeceleration:  3000
            plugin: mapPlugin
            center: QtPositioning.coordinate(34.162214, 107.902628) //todo: 地图中心 应该可以从配置中读取
            zoomLevel: 14

            // https://stackoverflow.com/a/49576756
            layer.enabled: true
            layer.samples: 8

            Component.onCompleted: {
                addMapItem(vehicle)
                addMapItem(home)
                resetMapToDefaults()
            }

            onCenterChanged:    handleChanges()
            onZoomLevelChanged: handleChanges()
            onWidthChanged:     handleChanges()
            onHeightChanged:    handleChanges()

            // 标记下载区域的矩形框
            MapRectangle {
                id:             mapBoundary
                border.width:   2
                border.color:   "red"
                color:          Qt.rgba(1,0,0,0.05)
                smooth:         true
                antialiasing:   true
            }

            // 航迹显示
            MapPolyline {
                id:         trajectoryPolyline
                line.width: 3
                line.color: "blue"
                //z: QGroundControl.zOrderTrajectoryLines
                visible:    true

                Connections {
                    target: _mapModel ? _mapModel.trajectoryPoints : null
                    function onPointAdded(coordinate) {
                        console.log("onPointAdded")
                        trajectoryPolyline.addCoordinate(coordinate)
                        vehicle.coordinate = coordinate
                        if (_followVehicle) {
                            _map.center = coordinate
                        }
                        homeVehicleLine.endCoordinate = coordinate
                    }
                    function onUpdateLastPoint(coordinate, azimuth) {
                        trajectoryPolyline.replaceCoordinate(trajectoryPolyline.pathLength() - 1, coordinate)
                        vehicle.coordinate = coordinate
                        // 机头方向应该是由航向角指定而不是方位角
                        // vehicle.sourceItem.rotation = azimuth
                        if (_followVehicle) {
                            _map.center = coordinate
                        }
                        homeVehicleLine.endCoordinate = coordinate
                    }
                    // TODO: 使用相应的信号来更新
                    // TODO: 需要测试
                    function onVehicleYawChanged(yaw) {
                        vehicle.rotation = yaw
                    }
                    function onPointsCleared(){
                        console.log("onPointsCleared")
                        trajectoryPolyline.path = []
                    }
                    function onHomeCoordinateChanged(coordinate) {
                        if (home.visible === false) {
                            home.visible = true
                        }

                        home.coordinate = coordinate
                        homeVehicleLine.beginCoordinate = coordinate
                    }
                }
            }
            MapDashLine {
                id: homeVehicleLine
                lineWidth: 1
                visible: home.visible
                showDistance: false
                Component.onCompleted: {
                    // 初始化时加入两个一样的点
                    homeVehicleLine.beginCoordinate = home.coordinate
                    homeVehicleLine.endCoordinate = home.coordinate
                }
            }

            // 缩放等级显示
            MapLabel {
                id: _labelZoomLevel
                map: _map
                anchors.bottom: _map.bottom
                anchors.left: _map.left
                text: "缩放等级： %1".arg(_map.zoomLevel)
            }

            //-- Show Set Info  显示图集信息
            Rectangle {
                id:                 infoView
                anchors.margins:    10
                anchors.right:      parent.right
                anchors.verticalCenter: parent.verticalCenter
                width:              tileInfoColumn.width  + (10 * 2)
                height:             tileInfoColumn.height + (10 * 2)
                color:              _rectColor
                radius:             10 * 0.5
                visible:            false

                property bool       _extraButton: {
                    if(!_root._currentSelection)
                        return false;
                    var curSel = _root._currentSelection;
                    return !_defaultSet && ((!curSel.complete && !curSel.downloading) || (!curSel.complete && curSel.downloading));
                }

                property real       _labelWidth:    10 * 10
                property real       _valueWidth:    10 * 14
                Column {
                    id:                 tileInfoColumn
                    anchors.margins:    10 * 0.5
                    spacing:            10 * 0.5
                    anchors.centerIn:   parent
                    // 显示 -- 不可修改名字的 Default Tile Set
                    MapLabel {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text:           _root._currentSelection ? _root._currentSelection.name : ""
                        font.pointSize: 10
                        horizontalAlignment: Text.AlignHCenter
                        visible:        _defaultSet
                    }
                    // 输入框 -- 用于修改除了 Default Tile Set 之外的图集名字
                    MapTextField {
                        id:             editSetName
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        visible:        !_defaultSet
                        text:           _root._currentSelection ? _root._currentSelection.name : ""
                    }
                    MapLabel {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        wrapMode:       Text.WordWrap
                        text: {
                            if(_root._currentSelection) {
                                if(_root._currentSelection.defaultSet)
                                    return "系统图块缓存";
                                else
                                    return "(" + _root._currentSelection.mapTypeStr + ")"
                            } else
                                return "";
                        }
                        horizontalAlignment: Text.AlignHCenter
                    }
                    //-- Tile Sets
                    Row {
                        spacing:    10
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    !_defaultSet //&& mapType !== QGroundControl.elevationProviderName
                        MapLabel {  text: "缩放级别："; width: infoView._labelWidth; }
                        MapLabel {  text: _root._currentSelection ? (_root._currentSelection.minZoom + " - " + _root._currentSelection.maxZoom) : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    Row {
                        spacing:    10
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    !_defaultSet
                        MapLabel {  text: "总计："; width: infoView._labelWidth; }
                        MapLabel {  text: (_root._currentSelection ? _root._currentSelection.totalTileCountStr : "") + " (" + (_root._currentSelection ? _root._currentSelection.totalTilesSizeStr : "") + ")"; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    Row {
                        spacing:    10
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    _root && _root._currentSelection && !_defaultSet && _root._currentSelection.uniqueTileCount > 0
                        MapLabel {  text: "唯一："; width: infoView._labelWidth; }
                        MapLabel {  text: (_root._currentSelection ? _root._currentSelection.uniqueTileCountStr : "") + " (" + (_root._currentSelection ? _root._currentSelection.uniqueTileSizeStr : "") + ")"; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }

                    Row {
                        spacing:    10
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    _root && _root._currentSelection && !_defaultSet && !_root._currentSelection.complete
                        MapLabel {  text: "已下载："; width: infoView._labelWidth; }
                        MapLabel {  text: (_root._currentSelection ? _root._currentSelection.savedTileCountStr : "") + " (" + (_root._currentSelection ? _root._currentSelection.savedTileSizeStr : "") + ")"; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    Row {
                        spacing:    10
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    _root && _root._currentSelection && !_defaultSet && !_root._currentSelection.complete && _root._currentSelection.errorCount > 0
                        MapLabel {  text: "错误数："; width: infoView._labelWidth; }
                        MapLabel {  text: _root._currentSelection ? _root._currentSelection.errorCountStr : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    //-- Default Tile Set
                    Row {
                        spacing:    10
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    _defaultSet
                        MapLabel { text: "占用空间："; width: infoView._labelWidth; }
                        MapLabel { text: _root._currentSelection ? _root._currentSelection.savedTileSizeStr  : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    Row {
                        spacing:    10
                        anchors.horizontalCenter: parent.horizontalCenter
                        visible:    _defaultSet
                        MapLabel { text: "图块数量："; width: infoView._labelWidth; }
                        MapLabel { text: _root._currentSelection ? _root._currentSelection.savedTileCountStr : ""; horizontalAlignment: Text.AlignRight; width: infoView._valueWidth; }
                    }
                    Row {
                        spacing:    10
                        anchors.horizontalCenter: parent.horizontalCenter
                        MapButton {
                            text:       "恢复下载"
                            visible:    _root._currentSelection && _root._currentSelection && !_defaultSet && (!_root._currentSelection.complete && !_root._currentSelection.downloading)
                            width:      10 * 16
                            onClicked: {
                                if(_root._currentSelection)
                                    _root._currentSelection.resumeDownloadTask()
                            }
                        }
                        MapButton {
                            text:       "取消下载"
                            visible:    _root._currentSelection && _root._currentSelection && !_defaultSet && (!_root._currentSelection.complete && _root._currentSelection.downloading)
                            width:      10 * 16
                            onClicked: {
                                if(_root._currentSelection)
                                    _root._currentSelection.cancelDownloadTask()
                            }
                        }
                        MapButton {
                            text:       "删除"
                            width:      10 * (infoView._extraButton ? 6 : 10)
                            onClicked:  {
                                deleteConfirmationDialogComponent.createObject(_root).open()
                            }
                            enabled:    _root._currentSelection ? (_root._currentSelection.savedTileSize > 0) : false
                        }
                        MapButton {
                            text:       "确定"
                            width:      10 * (infoView._extraButton ? 6 : 10)
                            visible:    !_defaultSet
                            enabled:    editSetName.text !== ""
                            onClicked: {
                                if(editSetName.text !== _currentSelection.name) {
                                    MapWidgetGlobal.mapEngineManager.renameTileSet(_currentSelection, editSetName.text)
                                }
                                leaveInfoView()
                                showList()
                            }
                        }
                        MapButton {
                            text:       _defaultSet ? "关闭" : "取消"
                            width:      10 * (infoView._extraButton ? 6 : 10)
                            onClicked: {
                                leaveInfoView()
                                showList()
                            }
                        }
                    }  // Row -- buttons
                }  // Column -- tileInfoColumn
            }  // Rectangle -- infoView  显示图集信息

            //-- Add new set  两张地图，用于缩放预览
            Item {
                id:             addNewSetView
                anchors.fill:   parent
                visible:        false

                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.leftMargin:     _margins
                    anchors.left:           parent.left
                    spacing:                _margins

                    MapButton {
                        text:       "显示缩放预览"
                        opacity: 0.6
                        visible:    !_showPreview
                        onClicked:  _showPreview = !_showPreview
                    }

                    Map {
                        id:                 minZoomPreview
                        width:              addNewSetView.width / 4
                        height:             addNewSetView.height / 4
                        center:             _map.center
                        activeMapType:      _map.activeMapType
                        zoomLevel:          sliderMinZoom.value
                        gesture.enabled:    false
                        visible:            _showPreview

                        property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1

                        plugin: Plugin { name: mapPlugin.name }

                        MapScale {
                            anchors.leftMargin:     10 / 2
                            anchors.bottomMargin:   anchors.leftMargin
                            anchors.left:           parent.left
                            anchors.bottom:         parent.bottom
                            mapControl:             parent
                            zoomButtonsVisible:     false
                        }

                        Rectangle {
                            anchors.fill:   parent
                            border.color:   _mapAdjustedColor
                            color:          "transparent"

                            MapLabel {
                                anchors.centerIn:   parent
                                map:                minZoomPreview
                                text:               "最小缩放等级： %1".arg(sliderMinZoom.value)
                            }
                            MouseArea {
                                anchors.fill:   parent
                                onClicked:      _showPreview = false
                            }
                        }
                    } // Map -- minZoomPreview
                    Map {
                        id:                 maxZoomPreview
                        width:              minZoomPreview.width
                        height:             minZoomPreview.height
                        center:             _map.center
                        activeMapType:      _map.activeMapType
                        zoomLevel:          sliderMaxZoom.value
                        gesture.enabled:    false
                        visible:            _showPreview

                        property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1

                        plugin: Plugin { name: mapPlugin.name }

                        MapScale {
                            anchors.leftMargin:     10 / 2
                            anchors.bottomMargin:   anchors.leftMargin
                            anchors.left:           parent.left
                            anchors.bottom:         parent.bottom
                            mapControl:             parent
                            zoomButtonsVisible:     false
                        }

                        Rectangle {
                            anchors.fill:   parent
                            border.color:   _mapAdjustedColor
                            color:          "transparent"

                            MapLabel {
                                anchors.centerIn:   parent
                                map:                maxZoomPreview
                                text:               "最大缩放等级： %1".arg(sliderMaxZoom.value)
                            }
                            MouseArea {
                                anchors.fill:   parent
                                onClicked:      _showPreview = false
                            }
                        }
                    } // Map -- maxZoomPreview
                }  // Column
            }  // Item -- Add new set  两张地图，用于缩放预览

            Text {
                id: coordDisplay
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                anchors.margins: 20
                color: "white"
                style: Text.Outline
                styleColor: "black"
                font.pixelSize: 14
            }

            MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                onPositionChanged: (mouse) => {
                    var coord = _map.toCoordinate(Qt.point(mouse.x, mouse.y));
                    //console.log(coord.latitude, coord.longitude);
                    coordDisplay.text = "Lat: " + coord.latitude.toFixed(6) + ", Lng: " + coord.longitude.toFixed(6);
                }
            }
        }  // Map

        // 添加新图集对话框
        //-- Add new set dialog
        Rectangle {
            anchors.margins:        10
            anchors.right:          _map.right
            anchors.verticalCenter: _map.verticalCenter
            width:                  _map.width / 3
            height:                 _map.height / 2
            color:                  _rectColor
            radius:                 3.5
            visible:                addNewSetView.visible

            MapLabel {
                id:                     addNewSetLabel
                anchors.margins:        10 / 2
                anchors.top:            parent.top
                anchors.left:           parent.left
                anchors.right:          parent.right
                wrapMode:               Text.WordWrap
                text:                   "添加图块集"
                font.pointSize:         10
                horizontalAlignment:    Text.AlignHCenter
                visible:                parent.visible
            }

            Flickable {
                id:                     addNewSetFlickable
                anchors.leftMargin:     10
                anchors.rightMargin:    anchors.leftMargin
                anchors.topMargin:      10 / 3
                anchors.bottomMargin:   anchors.topMargin
                anchors.top:            addNewSetLabel.bottom
                anchors.left:           parent.left
                anchors.right:          parent.right
                anchors.bottom:         parent.bottom
                clip:                   true
                contentHeight:          addNewSetColumn.height

                Column {
                    id:                 addNewSetColumn
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    spacing:            10 * 0.5

                    Column {
                        spacing:            10 * 0.25
                        anchors.left:       parent.left
                        anchors.right:      parent.right
                        MapLabel { text: "名称：" }
                        MapTextField {
                            id:             setName
                            anchors.left:   parent.left
                            anchors.right:  parent.right
                        }
                    }
                    /* 这里删除了地图类型和高程数据的相关内容 */
                    // 设置需要下载的地图的缩放范围
                    Rectangle {
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        height:         zoomColumn.height + 10 * 0.5
                        color:          _rectColor
                        border.color:   "white"
                        radius:         10 * 0.5
                        Column {
                            id:                 zoomColumn
                            spacing:            10 * 0.5
                            anchors.margins:    10 * 0.25
                            anchors.top:        parent.top
                            anchors.left:       parent.left
                            anchors.right:      parent.right

                            MapLabel {
                                text:           "最小--最大 缩放等级"
                                font.pointSize: 10
                                anchors.horizontalCenter: parent.horizontalCenter
                            }

                            Slider {
                                id:                         sliderMinZoom
                                anchors.left:               parent.left
                                anchors.right:              parent.right
                                height:                     sliderTouchArea * 1.25
                                from:                       minZoomLevel
                                to:                         maxZoomLevel
                                stepSize:                   1
                                live:                       true
                                property bool _updateSetting: false
                                Component.onCompleted: {
                                    sliderMinZoom.value = 10  // todo: 这里应该是可以设置为历史值的
                                    _updateSetting = true
                                }
                                onValueChanged: {
                                    if(sliderMinZoom.value > sliderMaxZoom.value) {
                                        sliderMaxZoom.value = sliderMinZoom.value
                                    }
                                    if (_updateSetting) {
                                        // Don't update setting until after Component.onCompleted since bad values come through before that
                                        // todo: 这里将 value 保存为历史值
                                    }
                                    handleChanges()
                                }
                                handle: Rectangle {
                                    x: sliderMinZoom.leftPadding + sliderMinZoom.visualPosition  * (sliderMinZoom.availableWidth - width)
                                    y: sliderMinZoom.topPadding  + sliderMinZoom.availableHeight * 0.5 - height * 0.5
                                    implicitWidth:  sliderTouchArea
                                    implicitHeight: sliderTouchArea
                                    radius:         sliderTouchArea * 0.5
                                    color:          _buttonColor
                                    border.width:   1
                                    border.color:   _buttonTextColor
                                    Label {
                                        text:               sliderMinZoom.value
                                        anchors.centerIn:   parent
                                        font.family:        fontFamily
                                        font.pointSize:     10
                                        color:              _buttonTextColor
                                    }
                                }
                            } // Slider - sliderMinZoom
                            Slider {
                                id:                         sliderMaxZoom
                                anchors.left:               parent.left
                                anchors.right:              parent.right
                                height:                     sliderTouchArea * 1.25
                                from:                       minZoomLevel
                                to:                         maxZoomLevel
                                stepSize:                   1
                                live:                       true
                                property bool _updateSetting: false
                                Component.onCompleted: {
                                    sliderMaxZoom.value = 10  // todo: 这里应该是可以设置为历史值的
                                    _updateSetting = true
                                }
                                onValueChanged: {
                                    if(sliderMaxZoom.value < sliderMinZoom.value) {
                                        sliderMinZoom.value = sliderMaxZoom.value
                                    }
                                    if (_updateSetting) {
                                        // Don't update setting until after Component.onCompleted since bad values come through before that
                                        // todo: 这里将 value 保存为历史值
                                    }
                                    handleChanges()
                                }
                                handle: Rectangle {
                                    x: sliderMaxZoom.leftPadding + sliderMaxZoom.visualPosition  * (sliderMaxZoom.availableWidth - width)
                                    y: sliderMaxZoom.topPadding  + sliderMaxZoom.availableHeight * 0.5 - height * 0.5
                                    implicitWidth:  sliderTouchArea
                                    implicitHeight: sliderTouchArea
                                    radius:         sliderTouchArea * 0.5
                                    color:          _buttonColor
                                    border.width:   1
                                    border.color:   _buttonTextColor
                                    Label {
                                        text:               sliderMaxZoom.value
                                        anchors.centerIn:   parent
                                        font.family:        fontFamily
                                        font.pointSize:     10
                                        color:              _buttonTextColor
                                    }
                                }
                            } // Slider - sliderMaxZoom
                            GridLayout {
                                columns:    2
                                rowSpacing: 10 * 0.5
                                MapLabel {
                                    text:           "图块数量："
                                    font.pointSize: 10
                                }
                                MapLabel {
                                    text:            MapWidgetGlobal.mapEngineManager.tileCountStr
                                    font.pointSize: 10
                                }

                                MapLabel {
                                    text:           "占用空间："
                                    font.pointSize: 10
                                }
                                MapLabel {
                                    text:           MapWidgetGlobal.mapEngineManager.tileSizeStr
                                    font.pointSize: 10
                                }
                            }  // GridLayout -- 图块数量：& 占用空间：
                        }  // Column -- zoomColumn -- Slider X 2
                    }  // Rectangle -- Border
                    MapLabel {
                        text:       "图块过多！"
                        visible:    _tooManyTiles
                        color:      _warningTextColor
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                    Row {
                        id: addButtonRow
                        spacing: 10
                        anchors.horizontalCenter: parent.horizontalCenter
                        // 下载按钮
                        MapButton {
                            text:       "下载"
                            width:      (addNewSetColumn.width * 0.5) - (addButtonRow.spacing * 0.5)
                            enabled:    !_tooManyTiles && setName.text.length > 0
                            onClicked: {
                                if(MapWidgetGlobal.mapEngineManager.findName(setName.text)) {
                                    duplicateName.visible = true
                                } else {
                                    MapWidgetGlobal.mapEngineManager.startDownload(setName.text, mapType);
                                    showList()
                                }
                            }
                        }
                        // 取消下载按钮
                        MapButton {
                            text:       "取消"
                            width:      (addNewSetColumn.width * 0.5) - (addButtonRow.spacing * 0.5)
                            onClicked: {
                                showList()
                            }
                        }
                    }
                }  // Column
            }  // Flickable -- addNewSetFlickable
        }  // Rectangle -- 添加新图集对话框 Add new set dialog

        // 地图下载按钮
        MapImageButton {
            id: buttonDownloadMapData
            imageSource: "qrc:/rc/image/mapDownload.png"
            width: 30
            height: width
            anchors.margins: 10
            anchors.top: _map.top
            anchors.left: _map.left
            enabled: true
            onClicked: {
                if (!tileSetListView.visible) {
                    tileSetListView.visible = true
                }
            }
        }

        MapImageButton {
            id: buttonFocusToHome
            imageSource: "qrc:/rc/image/home.png"
            width: 30
            height: width
            anchors.margins: 10
            anchors.top: _map.top
            anchors.left: buttonDownloadMapData.right
            enabled: true
            onClicked: {
                _followVehicle = false
                _map.center = home.coordinate
            }
        }

        MapImageButton {
            id: buttonFollowVehicle
            imageSource: "qrc:/rc/image/vehicle.png"
            width: 30
            height: width
            anchors.margins: 10
            anchors.top: _map.top
            anchors.left: buttonFocusToHome.right
            enabled: true
            Component.onCompleted: buttonFollowVehicle.setButtonChecked(_followVehicle)
            onClicked: {
                _followVehicle = !_followVehicle
                buttonFollowVehicle.setButtonChecked(_followVehicle)
                if (_followVehicle) {
                    _map.center = vehicle.coordinate
                }
            }
        }

        MapImageButton {
            id: buttonTest
            imageSource: "qrc:/rc/image/test.png"
            width: 30
            height: width
            anchors.margins: 10
            anchors.top: _map.top
            anchors.left: buttonFollowVehicle.right
            enabled: true
            onClicked: {
                console.log("test!!!")
            }
        }

        MapImageButton {
            id: buttonMapSettings
            imageSource: "qrc:/rc/image/settings.png"
            width: 30
            height: width
            anchors.margins: 10
            anchors.top: _map.top
            anchors.right: _map.right
            enabled: true
            onClicked: {
                mapSettingsDialogComponent.createObject(_root).open()
            }
        }

        // RC图集列表对话框
        Rectangle {
            id: tileSetListView
            anchors.margins: 10
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            //anchors.fill: parent
            width:              parent.width / 2
            height:             parent.height / 1.2
            color:              _rectColor
            radius: 3.5
            visible: false

            Flickable {
                id:                     _tileSetList
                boundsBehavior:         Flickable.StopAtBounds
                clip:                   true
                anchors.margins:    10
                anchors.top:        parent.top
                anchors.bottom:     _listButtonRow.top
                anchors.left:       parent.left
                anchors.right:      parent.right
                contentHeight:      _cacheList.height
                visible: parent.visible
                ButtonGroup {
                    id:             buttonGroup
                    buttons:        _cacheList.children
                }
                Column {
                    id:             _cacheList
                    width:          _tileSetList.width / 1.2
                    spacing:        10
                    anchors.horizontalCenter: parent.horizontalCenter
                    OfflineMapButton {
                        id:             firstButton
                        text:           "添加新图块集"
                        width:          _cacheList.width
                        height:         20
                        //currentSet:     null
                        visible: true
                        onClicked: {
                            _root._currentSelection = null
                            checked = true
                            addNewSet()
                            /*for test
                            var count = MapWidgetGlobal.mapEngineManager.tileSets.count
                            console.log("tileSets.count:" + count)
                            var items = MapWidgetGlobal.mapEngineManager.tileSets.get(0, count - 1);
                            for (var i = 0; i < items.length; ++i) {
                                console.log("tileSets" + i + "Name: " + items[i].name)
                            }*/
                        }
                    }
                    Repeater {
                        model: MapWidgetGlobal.mapEngineManager.tileSets
                        delegate: OfflineMapButton {
                            text:           object.name
                            size:           object.downloadStatus
                            tiles:          object.totalTileCount
                            complete:       object.complete
                            width:          firstButton.width
                            height:         firstButton.height
                            //currentSet:     _currentSelection
                            tileSet:        object
                            visible:        true
                            onClicked: {
                                _root._currentSelection = object
                                checked = true
                                showInfo()
                            }
                        }
                    }
                }
            }
            Row {
                id:                 _listButtonRow
                visible:            tileSetListView.visible
                spacing:            10
                //anchors.left:       parent.left
                //anchors.right:      parent.right
                anchors.bottom:     parent.bottom
                anchors.margins:    10
                anchors.horizontalCenter: parent.horizontalCenter
                // 一共 4 个按钮
                // 导入界面还有bug，按钮暂时隐藏
                MapButton {
                    text:           "导入"
                    width:          _cacheList.width * 0.25 - _listButtonRow.spacing  //_buttonSize
                    visible:        true  // 需要读取配置的值？
                    onClicked: {
                        MapWidgetGlobal.mapEngineManager.importAction = MapEngineManager.ActionNone
                        importDialog.open()
                    }
                }
                // 因为导入隐藏，所以导出也隐藏
                MapButton {
                    text:           "导出"
                    width:          _cacheList.width * 0.25 - _listButtonRow.spacing  //_buttonSize
                    visible:        true  // 需要读取配置的值？
                    onClicked: showExport()
                }
                MapButton {
                    text:           "选项"
                    width:          _cacheList.width * 0.25 - _listButtonRow.spacing  //_buttonSize
                    visible:        true
                    onClicked: { optionsDialogComponent.createObject(_root).open() }
                }
                MapButton {
                    text:           "退出"
                    width:          _cacheList.width * 0.25 - _listButtonRow.spacing  //_buttonSize
                    onClicked: tileSetListView.visible = false
                }
            }
        }  // Rectangle  RC图集列表对话框

        Rectangle {
            id: exporTilesView
            anchors.margins: 10
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            width:              parent.width / 2
            height:             parent.height / 1.2
            color:              _rectColor
            radius: 3.5
            visible: false

            //-- Export Tile Sets
            // 导出 按钮按下后显示
            Flickable {
                id:                 _exporTiles
                clip:               true
                visible:            parent.visible
                anchors.margins:    10
                anchors.top:        parent.top
                anchors.bottom:     _exportButtonRow.top
                anchors.left:       parent.left
                anchors.right:      parent.right
                contentHeight:      _exportList.height
                Column {
                    id:         _exportList
                    width:      Math.min(_exporTiles.width, (10 * 50).toFixed(0))
                    spacing:    10 * 0.5
                    anchors.horizontalCenter: parent.horizontalCenter
                    MapLabel {
                        text:           "选择要导出的图块集"
                        font.pointSize: 10
                    }
                    Item { width: 1; height: 10; }
                    Repeater {
                        model: MapWidgetGlobal.mapEngineManager.tileSets
                        delegate: MapCheckBox {
                            text:           object.name
                            checked:        object.selected
                            onClicked:      object.selected = checked
                            Connections {
                                // This connection should theoretically not be needed since the `checked: object.selected` binding should work.
                                // But for some reason when the user clicks the check box taht binding breaks. Which in turns causes
                                // Select All/None to update the internal state but check box visible state is out of sync
                                target:             object
                                function onSelectedChanged() { checked = object.selected }
                            }
                        }
                    }
                }
            }  // Flickable -- _exporTiles
            Row {
                id:                 _exportButtonRow
                visible:            _exporTiles.visible
                spacing:            _margins
                anchors.bottom:     parent.bottom
                anchors.margins:    10
                anchors.horizontalCenter: parent.horizontalCenter
                // 一共 4 个 按钮
                MapButton {
                    text:           "全部选中"
                    width:          _exportList.width * 0.25 - _exportButtonRow.spacing
                    onClicked:      MapWidgetGlobal.mapEngineManager.selectAll()
                }
                MapButton {
                    text:           "全部不选"
                    width:          _exportList.width * 0.25 - _exportButtonRow.spacing
                    onClicked:      MapWidgetGlobal.mapEngineManager.selectNone()
                }
                MapButton {
                    text:           "导出"
                    width:          _exportList.width * 0.25 - _exportButtonRow.spacing
                    enabled:        MapWidgetGlobal.mapEngineManager.selectedCount > 0
                    onClicked: {
                        fileDialogSave.title = "导出图块集"
                        fileDialogSave.selectExisting = false
                        fileDialogSave.open()
                    }
                }
                MapButton {
                    text:           "取消"
                    width:          _exportList.width * 0.25 - _exportButtonRow.spacing
                    onClicked:      showList()
                }
            }  // Row -- _exportButtonRow
        }  // exporTilesView -- exporTilesView
    }  // Item -- 地图显示区域

    // 导出地图集 进度显示
    Popup {
        id:                 exportToDiskProgress
        width:              _root.width * 0.666
        height:             _root.height * 0.333
        modal:              true
        focus:              true
        parent:             Overlay.overlay
        x:                  Math.round((_root.width  - width)  * 0.5)
        y:                  Math.round((_root.height - height) * 0.5)
        closePolicy:        Popup.NoAutoClose
        background: Rectangle {
            anchors.fill:   parent
            color:          "#282828"
            border.color:   "#707070"
            radius:         10
        }
        Column {
            id:                 exportCol
            spacing:            10
            width:              parent.width
            anchors.centerIn:   parent
            MapLabel {
                text:               MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionExporting ? "图块集导出进度" : "图块集导出完毕"
                font.family:        fontFamily
                font.pointSize:     10
                anchors.horizontalCenter: parent.horizontalCenter
            }
            ProgressBar {
                width:          parent.width * 0.45
                from:           0
                to:             100
                value:          MapWidgetGlobal.mapEngineManager.actionProgress
                anchors.horizontalCenter: parent.horizontalCenter
            }
            BusyIndicator {
                visible:        MapWidgetGlobal.mapEngineManager ? MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionExporting : false
                running:        MapWidgetGlobal.mapEngineManager ? MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionExporting : false
                width:          exportCloseButton.height
                height:         exportCloseButton.height
                anchors.horizontalCenter: parent.horizontalCenter
            }
            MapButton {
                id:             exportCloseButton
                text:           "关闭"
                width:          _buttonSize
                visible:        !MapWidgetGlobal.mapEngineManager.exporting
                anchors.horizontalCenter: parent.horizontalCenter
                onClicked: {
                    exportToDiskProgress.close()
                }
            }
        }  // Column -- exportCol
    }  // Popup -- exportToDiskProgress 导出地图集 进度显示

    // 导入地图集 进度显示
    Popup {
        id:                 importDialog
        width:              _root.width  * 0.666
        height:             importCol.height  * 1.5
        modal:              true
        focus:              true
        parent:             Overlay.overlay
        x:                  Math.round((_root.width  - width)  * 0.5)
        y:                  Math.round((_root.height - height) * 0.5)
        closePolicy:        Popup.NoAutoClose
        background: Rectangle {
            anchors.fill:   parent
            color:          "#282828"
            border.color:   "#707070"
            radius:         10
        }
        Column {
            id:                 importCol
            spacing:            10
            width:              parent.width
            anchors.centerIn:   parent

            MapLabel {
                text: {
                    if(MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionNone) {
                        return "图块集导入";
                    } else if(MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionImporting) {
                        return "图块集导入进度";
                    } else {
                        return "图块集导入完毕";
                    }
                }
                font.family:        fontFamily
                font.pointSize:     10
                anchors.horizontalCenter: parent.horizontalCenter
            }
            ProgressBar {
                width:          importCol.width * 0.45
                from:           0
                to:             100
                visible:        MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionImporting
                value:          MapWidgetGlobal.mapEngineManager.actionProgress
                anchors.horizontalCenter: parent.horizontalCenter
            }
            BusyIndicator {
                visible:        MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionImporting
                running:        MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionImporting
                width:          10 * 2
                height:         width
                anchors.horizontalCenter: parent.horizontalCenter
            }
            Column {
                id:                 mapSetButtons
                spacing:            10
                width:              10 * 24
                anchors.horizontalCenter: parent.horizontalCenter
                MapRadioButton {
                    text:           "添加到当前集"
                    checked:        !MapWidgetGlobal.mapEngineManager.importReplace
                    onClicked:      MapWidgetGlobal.mapEngineManager.importReplace = !checked
                    visible:        MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionNone
                }
                MapRadioButton {
                    text:           "替换当前集"
                    checked:        MapWidgetGlobal.mapEngineManager.importReplace
                    onClicked:      MapWidgetGlobal.mapEngineManager.importReplace = checked
                    visible:        MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionNone
                }
            }
            MapButton {
                text:           "关闭"
                width:          importCol.width * 0.333 - 10
                visible:        MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionDone
                anchors.horizontalCenter: parent.horizontalCenter
                onClicked: {
                    showList();
                    importDialog.close()
                }
            }
            Row {
                spacing:            _margins
                visible:            MapWidgetGlobal.mapEngineManager.importAction === MapEngineManager.ActionNone
                anchors.horizontalCenter: parent.horizontalCenter
                MapButton {
                    text:           "导入"
                    width:          importCol.width * 0.333 - 10
                    onClicked: {
                        //importDialog.close()
                        fileDialogLoad.title = "导入图块集"
                        fileDialogLoad.selectExisting = true
                        fileDialogLoad.open()
                    }
                }
                MapButton {
                    text:           "取消"
                    width:          importCol.width * 0.333 - 10
                    onClicked: {
                        showList();
                        importDialog.close()
                    }
                }
            }

        }  // Column -- importCol
    }  // Popup -- importDialog 导入地图集 进度显示
}
